package org.rc.model;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.NotSaved;
import com.googlecode.objectify.annotation.Unindexed;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Id;

public class Result implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    private Long id;
    
    private Key<Athlete> athlete;

    @Unindexed
    private String recordedAthleteName;

    @Unindexed
    private String category;

    private String club;

    private Integer place;

    private Key<Race> race;
    
    @Unindexed
    private Integer hours;

    @Unindexed
    private Integer min;

    @Unindexed
    private Integer sec;

    @Unindexed
    private Date date;

    private Key<ResultsFile> importedBy;

    @Unindexed
    private Long secondsPerMilePace;
    
    @Unindexed
    private Double topPercentile;
    
    @NotSaved  
    private Race raceBean;
    
    /**
     * Returns a readable version of the time hh:mm:ss
     * @return
     */
    public String getReadableTime() {
        StringBuilder sb = new StringBuilder();
        sb.append(hours);
        sb.append(":");
        if(min<10) {
            sb.append("0");
        }
        sb.append(min);
        sb.append(":");
        if(sec<10) {
            sb.append("0");
        }
        sb.append(sec);
        return sb.toString();
    }

    /**
     * Get the total time in seconds
     * @return 
     */
    public long getTimeInSeconds() {
        long result = 0;
        if(hours!=null)
            result+= hours * 60 * 60;
        if(min!=null)
            result+= min * 60;
        if(sec!=null)
            result+= sec;
        return result;
    }
    
    /**
     * Get the ID
     * @return
     */
    public Long getId() {
        return id;
    }

    /**
     * set the ID
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the athlete key
     */
    public Key<Athlete> getAthlete() {
        return athlete;
    }

    /**
     * @param athlete the athlete key to set
     */
    public void setAthlete(Key<Athlete> athlete) {
        this.athlete = athlete;
    }

    /**
     * @return the race
     */
    public Key<Race> getRace() {
        return race;
    }

    /**
     * @param race the race to set
     */
    public void setRace(Key<Race> race) {
        this.race = race;
    }

    /**
     * @return the hours
     */
    public Integer getHours() {
        return hours;
    }

    /**
     * @param hours the hours to set
     */
    public void setHours(Integer hours) {
        this.hours = hours;
    }

    /**
     * @return the min
     */
    public Integer getMin() {
        return min;
    }

    /**
     * @param min the min to set
     */
    public void setMin(Integer min) {
        this.min = min;
    }

    /**
     * @return the sec
     */
    public Integer getSec() {
        return sec;
    }

    /**
     * @param sec the sec to set
     */
    public void setSec(Integer sec) {
        this.sec = sec;
    }

    /**
     * @return the importedBy
     */
    public Key<ResultsFile> getImportedBy() {
        return importedBy;
    }

    /**
     * @param importedBy the importedBy to set
     */
    public void setImportedBy(Key<ResultsFile> importedBy) {
        this.importedBy = importedBy;
    }

    /**
     * @return the category
     */
    public String getCategory() {
        return category;
    }

    /**
     * @param category the category to set
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * @return the club
     */
    public String getClub() {
        return club;
    }

    /**
     * @param club the club to set
     */
    public void setClub(String club) {
        this.club = club;
    }

    /**
     * @return the place
     */
    public Integer getPlace() {
        return place;
    }

    /**
     * @param place the place to set
     */
    public void setPlace(Integer place) {
        this.place = place;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the recordedAthleteName
     */
    public String getRecordedAthleteName() {
        return recordedAthleteName;
    }

    /**
     * @param recordedAthleteName the recordedAthleteName to set
     */
    public void setRecordedAthleteName(String recordedAthleteName) {
        this.recordedAthleteName = recordedAthleteName;
    }

    /**
     * @return the secondsPerMilePace
     */
    public Long getSecondsPerMilePace() {
        return secondsPerMilePace;
    }

    /**
     * @param secondsPerMilePace the secondsPerMilePace to set
     * Average pace for the race
     */
    public void setSecondsPerMilePace(Long secondsPerMilePace) {
        this.secondsPerMilePace = secondsPerMilePace;
    }

    /**
     * @return the topPercentile
     * example 10 means finishing in top 10%
     */
    public Double getTopPercentile() {
        return topPercentile;
    }

    /**
     * @param topPercentile the topPercentile to set
     * example 10 means finishing in top 10%
     */
    public void setTopPercentile(Double topPercentile) {
        this.topPercentile = topPercentile;
    }

    /**
     * @return the raceBean
     */
    public Race getRaceBean() {
        return raceBean;
    }

    /**
     * @param raceBean the raceBean to set
     */
    public void setRaceBean(Race raceBean) {
        this.raceBean = raceBean;
    }

}
